package com.ruoyi.fun.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.fun.service.ILogisticsTrackingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 物流跟踪Controller
 *
 * @author ruoyi
 */
@Api(tags = "物流跟踪管理")
@RestController
@RequestMapping("/app/logistics")
public class LogisticsTrackingController extends BaseController {

    @Autowired
    private ILogisticsTrackingService logisticsTrackingService;

    /**
     * 根据订单号获取物流跟踪信息
     */
    @ApiOperation("根据订单号获取物流跟踪信息")
    @GetMapping("/tracking/{orderNo}")
    public AjaxResult getLogisticsTracking(
            @ApiParam(value = "订单号", required = true)
            @PathVariable String orderNo) {
        return AjaxResult.success(logisticsTrackingService.getLogisticsTrackingByOrderNo(orderNo));
    }

    /**
     * 直接调用外部物流API（用于测试）
     */
    @ApiOperation("直接调用外部物流API")
    @PostMapping("/external")
    public AjaxResult callExternalApi(
            @ApiParam(value = "快递公司编码", required = true)
            @RequestParam String com,
            @ApiParam(value = "快递单号", required = true)
            @RequestParam String nu,
            @ApiParam(value = "收件人手机号后四位", required = true)
            @RequestParam String phone) {
        return AjaxResult.success(logisticsTrackingService.callExternalLogisticsApi(com, nu, phone));
    }
}